package de.gameduell.framework.modules 
{
	import flash.events.Event;
	/**
	 * ...
	 * @author Ferry Trunschke
	 */
	public class MonoBehaviour extends ModuleAdapter {
		
		public var parentNode:MonoBehaviour;
		public var childNodes:Array = [];
		
		public function MonoBehaviour(parentNode:MonoBehaviour = null) {
			this.parentNode = parentNode;
		}

		public function addChildNode(childNode:MonoBehaviour) {
			childNodes.push(childNode);
		} 

		public override function broadcastEvent(event:Event) {

			// send to childs
			if (parentNode == null) {
				this.handleEvent(event);
			}
			// bubble up
			else {
			   parentNode.broadcastEvent(event);
			}
			
		}

		public override function handleEvent(event:Event) {
			for each(var childNode:MonoBehaviour in childNodes) {
			   childNode.handleEvent(event);
			}
		}		
		
	}

}